package com.duck.inspection.enums;

import lombok.Getter;
import java.util.Arrays;

@Getter
public enum DuckAgeStage {
    // 格式参数说明：
    // code, baseMonth, displayName,
    // minWeight, maxWeight (kg)
    // minTibia, maxTibia (cm)
    // minKeel, maxKeel (cm)
    // minChestDepth, maxChestDepth (cm)
    // minChestWidth, maxChestWidth (cm)

    WEEK1(1, 0.25, "1周龄",
            0.15, 0.25,   // 体重（商品肉鸭标准）
            2.5, 3.5,     // 胫长
            3.0, 4.0,     // 龙骨
            3.0, 4.0,      // 胸深
            3.5, 4.5),     // 胸宽

    WEEK2(2, 0.5, "2周龄",
            0.35, 0.55,
            3.5, 4.5,
            4.5, 5.5,
            4.0, 5.0,
            4.5, 5.5),

    WEEK3(3, 0.75, "3周龄",
            0.65, 0.85,
            4.5, 5.5,
            5.5, 6.5,
            5.0, 6.0,
            5.5, 6.5),

    MONTH1(4, 1.0, "1个月",
            0.9, 1.2,   // 体重范围（原错误值为0.7-1.0）
            5.0, 6.0,   // 胫长
            6.5, 7.5,   // 龙骨长
            6.0, 7.0,   // 胸深
            6.5, 7.5),   // 胸宽

    MONTH2(5, 2.0, "2个月",
            1.8, 2.2,
            6.5, 7.5,
            7.5, 8.5,
            7.0, 8.0,
            7.5, 8.5),

    MONTH3(6, 3.0, "3个月",
            2.5, 3.0,
            7.5, 8.5,
            8.5, 9.5,
            8.0, 9.0,
            8.5, 9.5),

    MONTH4(7, 4.0, "4个月",
            3.2, 3.8,
            8.5, 9.5,
            9.5, 10.5,
            9.0, 10.0,
            9.5, 10.5),

    MONTH5(8, 5.0, "5个月",
            3.8, 4.2,
            9.5, 10.5,
            10.5, 11.5,
            10.0, 11.0,
            10.5, 11.5),

    MONTH6_PLUS(9, 6.0, "6个月以上",
            4.5, 5.5,
            10.5, 12.0,
            11.5, 13.0,
            11.0, 13.0,
            11.5, 13.0);

    private final int code;
    private final double baseMonth;
    private final String displayName;

    // 生长指标标准范围
    private final double minWeight;
    private final double maxWeight;
    private final double minTibia;
    private final double maxTibia;
    private final double minKeel;
    private final double maxKeel;
    private final double minChestDepth;
    private final double maxChestDepth;
    private final double minChestWidth;
    private final double maxChestWidth;

    DuckAgeStage(int code, double baseMonth, String displayName,
                 double minWeight, double maxWeight,
                 double minTibia, double maxTibia,
                 double minKeel, double maxKeel,
                 double minChestDepth, double maxChestDepth,
                 double minChestWidth, double maxChestWidth) {
        this.code = code;
        this.baseMonth = baseMonth;
        this.displayName = displayName;
        this.minWeight = minWeight;
        this.maxWeight = maxWeight;
        this.minTibia = minTibia;
        this.maxTibia = maxTibia;
        this.minKeel = minKeel;
        this.maxKeel = maxKeel;
        this.minChestDepth = minChestDepth;
        this.maxChestDepth = maxChestDepth;
        this.minChestWidth = minChestWidth;
        this.maxChestWidth = maxChestWidth;
    }

    // 生成完整的标准描述
    public String getStandardDesc() {
        return String.format(
                "体重%.2f-%.2fkg | 胫长%.1f-%.1fcm | 龙骨长%.1f-%.1fcm | 胸深%.1f-%.1fcm | 胸宽%.1f-%.1fcm",
                minWeight, maxWeight,
                minTibia, maxTibia,
                minKeel, maxKeel,
                minChestDepth, maxChestDepth,
                minChestWidth, maxChestWidth
        );
    }

    public static DuckAgeStage fromCode(int code) {
        return Arrays.stream(values())
                .filter(e -> e.code == code)
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效年龄编码: " + code));
    }
}